package com.lonty.vote.service;

import com.lonty.vote.mapper.master.UserMapper;
import com.lonty.vote.model.User;
import com.lonty.vote.util.UUIDUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * @Author 陈璇
 * @Date 2020/5/25 10:08
 * @Version 1.0
 */
@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    /**
     * 登录
     * @return
     */
    public User login(String token){
        //判断是否为新用户 为新用户就新增，否则返回
        User user = userMapper.getUser(token);
        if(user != null){
            return user;
        }
        user = new User();
        user.setId(UUIDUtil.randomID());
        user.setToken(token);
        user.setIsBackups(0);
        userMapper.saveUser(user);
        return user;
    }

}
